#pragma once

#include "Motion/JumpDefines.h"
#include "Motion/MotionUtils/MotionUtils.h"
#include "Motion/MoveDefines.h"
#include "Motion/PointMoveHandler/PointMoveHandler.h"
#include "MotionAutoTask.h"

#include "Utils/UnitConverter/UnitConverter.h"

#include <chrono>
#include <cstddef>
#include <memory>

namespace edm {

namespace move {

// 此类应当不允许被暂停
// 即使允许被暂停, 再次继续时, 数据也无意义了
class PRBSAutoTask final : public AutoTask {
public:
    PRBSAutoTask(size_t axis_idx, std::shared_ptr<std::vector<int16_t>> prbs_data_ptr);
    ~PRBSAutoTask() noexcept override = default;

    bool pause() override;
    bool resume() override;
    bool stop(bool immediate [[maybe_unused]] = false) override;

    bool is_normal_running() const override {
        return state_ == State::Running;
    }
    bool is_pausing() const override { return false; }
    bool is_paused() const override { return state_ == State::Paused; }
    bool is_resuming() const override { return false; }
    bool is_stopping() const override { return state_ == State::Stopping; }
    bool is_stopped() const override { return state_ == State::Stopped; }
    bool is_over() const override { return is_stopped(); }

    void run_once() override ;

    double get_progress_percent() const override;

private:
    size_t axis_idx_{0}; // 作用轴索引 
    std::shared_ptr<std::vector<int16_t>> prbs_data_ptr_{nullptr};
    int curr_idx_{0}; // 当前运行的数据索引
    axis_t start_cmd_axis_{0};

    double ratio_{1.0};

    enum class State {
        Running,
        Paused,
        Stopping,
        Stopped
    };

    State state_{State::Running};
};

} // namespace move

} // namespace edm
